package com.crowntit.infrastructure.adapter.port;

import com.crowntit.domain.goods.adapter.port.IOriProductPort;
import com.crowntit.domain.goods.model.entity.GoodsConfigInfoEntity;
import com.crowntit.domain.order.adapter.port.IProductPort;
import com.crowntit.domain.order.model.entity.ProductEntity;
import com.crowntit.infrastructure.gateway.ProductRPC;
import com.crowntit.infrastructure.gateway.dto.ProductDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Component
public class ProductPort implements IProductPort, IOriProductPort {

    @Resource
    public ProductRPC productRPC;

    @Override
    public ProductEntity queryProductByProductId(String productId) {
        ProductDTO productDTO = productRPC.queryProductByProductId(productId);
        return ProductEntity.builder()
                .productId(productDTO.getProductId())
                .productName(productDTO.getProductName())
                .productDesc(productDTO.getProductDesc())
                .price(productDTO.getPrice())
                .build();
    }

    @Override
    public GoodsConfigInfoEntity.Goods queryGoodsInfo(String productId) {
        ProductDTO productDTO = productRPC.queryProductByProductId(productId);
        return GoodsConfigInfoEntity.Goods.builder()
                .goodsId(productDTO.getProductId())
                .goodsName(productDTO.getProductName())
                .originalPrice(productDTO.getPrice())
                .deductionPrice(BigDecimal.ZERO)
                .payPrice(productDTO.getPrice())
                .build();
    }
}
